package cn.itcast.web.controller.stat;

import cn.itcast.service.stat.StatService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stat")
public class StatController extends BaseController {


    @Reference
    private StatService statService;


    /*
        url:/stat/toCharts.do?chartsType=factory
        作用：进入对应的报表页面中
        参数：报表页面的类型
        返回值：
     */
    @RequestMapping("/toCharts")
    public String toCharts(String chartsType){
        return "stat/stat-"+chartsType;
    }


    /*
      url:/stat/getFactoryData
      作用：获取厂家的销售额
      参数：没有
      返回值：厂家销售额的json字符串
   */
    @RequestMapping("/getFactoryData")
    @ResponseBody
    public List<Map<String,Object>> getFactoryData(){
        List<Map<String, Object>> factoryData = statService.getFactoryData(getLoginUserCompanyId());
        return factoryData;
    }


    /*
     url:/stat/getSellData
     作用：获取产品的销售额
     参数：没有
     返回值：产品销售额的json字符串
  */
    @RequestMapping("/getSellData")
    @ResponseBody
    public List<Map<String,Object>> getSellData(){
        List<Map<String, Object>> sellData = statService.getSellData(getLoginUserCompanyId());
        return sellData;
    }


    /*
   url:/stat/getOnlineData
   作用：按小时统计访问人数
   参数：没有
   返回值：按小时统计访问人数的json字符串
*/
    @RequestMapping("/getOnlineData")
    @ResponseBody
    public List<Map<String,Object>> getOnlineData(){
        List<Map<String, Object>> onlineData = statService.getOnlineData();
        return onlineData;
    }
}
